<?php
class my_ques_list {
	var $ques_finish_count=8;
	var $ques_not_finish_count=8;
	var $ques_finish_info=array();
	var $ques_unfinish_info=array();
	var $page_count=20;
	var $list_title=false;
	var $page=false;
	var $finish_flag=false;
	var $page_tpl=false;
	var $user_id=false;
	function get_list() {
		global $user,$game_id,$server_id;
		$user_id=$user->id;
		$sql="select id,title,ask_time from question_info where user_id=$user_id and solution_flag!=1 and game_id='".$game_id."' and server_id='".$server_id."' order by ask_time desc limit 10";
		$this->ques_unfinish_info=sql_get_arr($sql,__LINE__);
		$sql="select id,title,ask_time from question_info where user_id=$user_id and solution_flag=1 and game_id='".$game_id."' and server_id='".$server_id."' order by ask_time desc limit 10";
		$this->ques_finish_info=sql_get_arr($sql,__LINE__);
	}
	function get_list_page($finish_flag,$page,$page_count=-1) {
		global $user,$game_id,$server_id;
		if($page_count==-1) $page_count=$this->page_count;
		$start=($page-1)*$page_count;
		$this->page=$page;
		$this->finish_flag=$finish_flag;
		$user_id=$user->id;
		$this->user_id=$user_id;
		$sql="select id,title,ask_time from question_info where user_id=$user_id and game_id='".$game_id."' and server_id='".$server_id."' ";
		if($finish_flag==1) $sql.=" and solution_flag=1 ";
		else  $sql.=" and solution_flag!=1 ";
		$sql.=" order by ask_time desc limit $start,$page_count";
		$this->ques_list_page=sql_get_arr($sql,__LINE__);
		if($finish_flag) $this->list_title='已处理的问题';
		if(!$finish_flag) $this->list_title='正在处理的问题';
		$this->get_page();
	}
	function get_page(){
		global $user,$game_id,$server_id;
		//获取总页数:
		$user_id=$this->user_id;
		$finish_flag=$this->finish_flag;
		$sql="select count(*) from question_info where user_id=$user_id and solution_flag=$finish_flag and game_id='".$game_id."' and server_id='".$server_id."' ";
		$row=sql_get_one($sql,__LINE__);
		$total=$row['count(*)'];
		$total_page=ceil($total/$this->page_count);
//		if($total_page<2) return;

		$this->page_tpl='<table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>';
		//首页
		$this->page_tpl.='
		<td width="19%" align="center"><a href="my_ques.php?finish='.$this->finish_flag.'">[首页]</a></td>
		';
		
		//上一页
		if($this->page>1) $last_page_no=$this->page-1;
		else $last_page_no=$this->page;		
		$this->page_tpl.='
		<td width="14%" align="center"><a href="my_ques.php?finish='.$this->finish_flag.'&page='.$last_page_no.'">[上页]</a></td>
		';
		
		//中间
		$this->page_tpl.='<td width="34%" align="center">';

		for($i=$this->page-2;$i<$this->page+6 && $i<=$total_page;$i++)
		{
			if($i>0)
			{
				if($i==$this->page) $this->page_tpl.="<font color=red><b>[$i]</b></font> ";
				else $this->page_tpl.='<A href="my_ques.php?finish='.$this->finish_flag.'&page='.$i.'">['.$i.']</a> ';
			}
		}
		$this->page_tpl.='</td>';
		
		//下一页
		if($this->page<$total_page) $next_page_no=$this->page+1;
		else $next_page_no=$this->page;		
		$this->page_tpl.='
		<td width="14%" align="center"><a href="my_ques.php?finish='.$this->finish_flag.'&page='.$next_page_no.'">[下页]</a></td>
		';
				
		//尾页
		$this->page_tpl.='
		<td width="19%" align="center"><a href="my_ques.php?finish='.$this->finish_flag.'&page='.$total_page.'">[尾页]</a></td>
		';
		
		$this->page_tpl.='
				</tr>
		</table>
		';
	}	
}
?>